package com.example.teesystem.controller;

import com.example.teesystem.common.utils.Response;
import com.example.teesystem.common.utils.ResultCode;
import com.example.teesystem.entity.BoatRank;
import com.example.teesystem.entity.vo.boatGame.BoatCheck;
import com.example.teesystem.entity.vo.boatGame.BoatSearch;
import com.example.teesystem.service.BoatRankService;
import com.example.teesystem.service.BoatService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author pxr
 * @data 26/11/2022 下午12:51
 */

@RestController
@RequestMapping(value = "/tee/boatGame", produces = "application/json; charset=utf-8")
@RequiredArgsConstructor
@Validated
public class BoatGameController {
    private final BoatService boatService;
    private final BoatRankService boatRankService;

    @PostMapping(value = "/search")
    public Response search(@RequestBody BoatSearch boatSearch){
        return boatService.boatSearch(boatSearch);
    }

    @PostMapping(value = "/check")
    public Response check(@RequestBody BoatCheck boatCheck){
        return boatService.check(boatCheck);
    }

    @PostMapping(value = "/end")
    public Response end(@RequestBody BoatCheck boatCheck){
        return boatService.end(boatCheck);
    }

    @PostMapping(value = "/rank")
    public Response end(@RequestBody Map<String,Integer> map){
        Integer courseId = map.get("courseId");
        if(courseId==null){
            return Response.error(ResultCode.PARAMETER_ERROR);
        }
        return boatRankService.boatRank(courseId);
    }
}
